package com.hui.servlet;

import com.hui.entity.Student;
import com.hui.service.StudentService;
import com.hui.util.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/06/20/13:18
 * @Description:
 */
@WebServlet(name = "SelectStudentServlet", urlPatterns = "/selectStudent")
public class SelectStudentServlet extends HttpServlet {
    private StudentService studentService = ServiceFactory.getStudentService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        List<Student> studentList = studentService.getStudentById(Integer.parseInt(id));
        // 保存到session中
        req.getSession().setAttribute("studentList", studentList);
        resp.sendRedirect("home.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

}
